<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>怡臣 | 店铺管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/Public/admin/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <!--link rel="stylesheet" href="/Public/admin/adminlte/plugins/ionicons/ionicons.min.css"-->
    <!-- Theme style -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/Public/admin/adminlte/plugins/html5shiv/html5shiv.min.js"></script>
    <script src="/Public/admin/adminlte/plugins/html5shiv/respond.min.js"></script>
    <![endif]-->

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">{$local_name}</h3>
                <div class="form-inline pull-right">
                    <form action="{:U('Flashsales/getProducts',array('local_id'=>$local_id,'order_field'=>'product_id','order'=>$order,'date'=>$date), '')}"
                          method="get" pjax-container="">
                        <input type="hidden" name="beginTime" value="{$limitTime.beginTime}">
                        <input type="hidden" name="endTime" value="{$limitTime.endTime}">
                        <fieldset>
                            <select class="form-control" name="search_field" style="height: 30px; font-size: 12px;">
                                <option value="a.p_name"
                                <if condition="$search_field eq 'a.p_name'">selected="selected"</if>
                                >货品名称</option>
                                <option value="barcode"
                                <if condition="$search_field eq 'barcode'">selected="selected"</if>
                                >条码</option>
                                <option value="bn"
                                <if condition="$search_field eq 'bn'">selected="selected"</if>
                                >BN</option>
                            </select>
                            <div class="input-group input-group-sm">
                                <div class="input-group input-group-sm">
                                    <input type="text" class="form-control" placeholder="" name="search"
                                           value="{$search}">
                                </div>
                            </div>

                            <div class="input-group input-group-sm">
                                <div class="input-group-btn">
                                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>

            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                    <tbody>
                    <tr>
                        <th><input type="checkbox" class="grid-select-all"></th>
                        <th>货品ID<a class="fa fa-fw fa-sort"
                                   href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'product_id','order'=>$order,'date'=>$date), '')}"></a>
                        </th>
                        <th>商品ID<a class="fa fa-fw fa-sort"
                                   href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'goods_id','order'=>$order,'date'=>$date), '')}"></a>
                        </th>
                        <th>名称</th>
                        <th>商品分类</th>
                        <th>图片</th>
                        <th>活动类型</th>
                        <th>条码<a class="fa fa-fw fa-sort"
                                 href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'barcode','order'=>$order,'date'=>$date), '')}"></a>
                        </th>
                        <th>BN<a class="fa fa-fw fa-sort"
                                 href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'bn','order'=>$order,'date'=>$date), '')}"></a>
                        </th>
                        <th>销售价<a class="fa fa-fw fa-sort"
                                  href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'price','order'=>$order,'date'=>$date), '')}"></a></th>
                        <th>市场价<a class="fa fa-fw fa-sort"
                                  href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'marketprice','order'=>$order,'date'=>$date), '')}"></a></th>
                        <th>折后价<a class="fa fa-fw fa-sort"
                                  href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'discount','order'=>$order,'date'=>$date), '')}"></a></th>
                        <th>库存<a class="fa fa-fw fa-sort"
                                 href="{:U('Flashsales/getProducts',array('p'=>$p,'order_field'=>'store','order'=>$order,'date'=>$date), '')}"></a></th>
                        <th>冻结库存</th>
                    </tr>
                    <volist name="list" id="vo">
                        <tr class="cg-product-tr"
                            <?php $state = activityByStoreId($vo['store_pid'], $vo['local_id'], $limitTime); ?>
                        <?php if (substr($state, 4, 1) === '1' || substr($state, 3, 1) === '1' || substr($state, 2, 1) === '1'){
                                            echo "style='text-decoration:line-through'";
                                        }
                                        ?>>
                        <td><input type="checkbox"
                            <?php if (substr($state, 4, 1) === '1' || substr($state, 3, 1) === '1' || substr($state, 2, 1) === '1'){
                                            echo "disabled='disabled'";
                                        }
                                        ?>
                            class="grid-item" data-id="{$vo.store_pid}" data-name="{$vo.p_name}"
                            data-price="{$vo.price}" data-store="{$vo.store}" data-freez="{$vo.freez}"
                            <if condition="$vo['is_show'] eq true">checked</if> ></td>

                            <td>{$vo.product_id}</td>
                            <td>{$vo.goods_id}</td>
                            <td>{$vo.p_name}</td>
                            <td>{$vo.cat_name}</td>
                            <td><img style="width: 80px;" src="{$vo.goods_id|getThumb=###}" alt=""></td>
                        <td>
                            <?php
                            if (substr($state, 0, 1) === '1') {
                                                echo '<span class="badge bg-green">订单促销</span>';
                            }
                            if (substr($state, 3, 1) === '1') {
                            echo '<span class="badge bg-green">商品促销</span>';
                            }
                            if (substr($state, 2, 1) === '1') {
                            echo '<span class="badge bg-green">闪购</span>';
                            }
                            if (substr($state, 4, 1) === '1') {
                            echo '<span class="badge bg-green">组合促销</span>';
                            }
                            if (substr($state, 1, 1) === '1') {
                            echo '<span class="badge bg-green">专题商品包</span>';
                            }
                            ?>
                        </td>
                            <td>{$vo.barcode}</td>
                            <td>{$vo.bn}</td>
                            <td>{$vo.price}</td>
                            <td>{$vo.marketprice}</td>
                            <td>{$vo.discount}</td>
                            <td>{$vo.store}</td>
                            <td>{$vo.freez}</td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
            <div class="box-footer clearfix">
                <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                <a class="btn btn-sm btn-info batch-choose">保存</a>
                <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>
                {$page}
            </div>
            <!-- /.box-body -->
        </div>
    </div>
</div>
</body>
<style type="text/css">
    .rush-rule{
        height: auto;
        overflow: hidden;
        border: 1px solid #dedede;
        position: relative;
        padding-bottom: 46px;
    }
    .rush-rule dt{
        border-bottom: 1px solid #dedede;
        height: auto;
        overflow: hidden;
    }
    .rush-rule dd{
        height: auto;
        overflow: hidden;
        display: flex;
        border-bottom: 1px solid #dedede;
    }
    .rush-rule dt div.rush-list{
        padding: 10px 5px;

    }
    .rush-rule dd div.rush-list{
        padding: 10px 5px;
        display: table-cell;

    }
    .rush-rule dd div.rush-list p{
        line-height: inherit;
    }
    .rush-rule dd.rush-rule-btn{
        position: absolute;
        bottom: 0px;
        left:0;
        width: 100%;
        border-bottom: none;
    }
    .rush-rule dd div.rush-list p input{
        padding-left: 5px;
        margin-left: 10px;
    }
    .rush-rule dd div.rush-list p label{
        font-weight: 400;
    }
    .rush-rule div.rush-list{
        border-left: 1px solid #dedede;
        float: left;
        text-align: center;
        height: auto;
        overflow: hidden;
    }
    .rush-rule div.rush-list:first-child{
        border-left: none;
    }
    .rush-rule .rushTime-btn{
        margin: 5px 10px;
    }
</style>
<script src="/Public/admin/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="/Public/admin/adminlte/bootstrap/js/bootstrap.min.js"></script>

<!-- AdminLTE App -->
<script src="/Public/admin/adminlte/dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="/Public/admin/adminlte/dist/js/demo.js"></script>
<script src="/Public/admin/adminlte/plugins/iCheck/icheck.min.js"></script>
<script src="/Public/admin/js/common.js?v=20170331001"></script>
<script data-exec-on-popstate>
    $(function () {
		var chids = parent.$("#yc-goods-ids").val();
        var ychser = new YcChoser();
        ychser.setChosenIds(chids);
		$(".grid-item").each(function(){
            if(ychser.isRepeat($(this).attr("data-id"))){
                $(this).prop("checked", "checked");
            }
        });
		
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });
        $('.grid-refresh').click(function () {
            window.location.reload();
        });

        $('.batch-choose').on('click', function (e) {
            if (!confirm("是否保存？")) {
                return false;
            }
            $(".grid-item").each(function (i) {
				var id = $(this).data('id'); // id
                var name = $(this).data('name'); // 商品名称
                var price = $(this).data('price'); // 价格
				var store = $(this).data('store'); // 库存
                var freez = $(this).data('freez'); // 库存
				var flag = ychser.isRepeat($(this).attr("data-id"));
                if(flag && !$(this).is(':checked')){
                    ychser.remove();
                    parent.$('.ui-sortable').children("li").eq(ychser.getPosition()).remove();
                }else if ($(this).is(':checked') && !flag) {
                    ychser.add($(this).attr("data-id"));
					var html = '';
					html += '<li class="one-produc">';
					html += '<input type="hidden" name="store_pid[]" value="'+id+'">';
					html += '<a class="text" href="javascript:;" title="'+name+'">'+name+'</a>';
					html += '<small class="label label-warning"> 原价 : '+price+'</small>'
					html += '闪购价 : <input type="text" class="sgprice"  data-price="'+price+'" onblur="validateShanGou(this, \'sg-cost\');" name="promotion_price[]" >';

					html += ' <small class="label label-success"> 可用库存 : '+(store-freez)+'</small>';
					html += ' 货品数量 : <span class="text shuliang"><input type="text" data-num="'+(store-freez)+'" class="geshu" name="initnum[]" onblur="validateShanGou(this, \'gd-num\');"/></span>';
					html += '<div class="tools">';
					html += '<i class="fa fa-trash-o icondel" data-id="'+id+'" onclick="deleteProduct(this)"></i>';
					html += '</div>';
					html += '</li>';
					parent.$('.ui-sortable').append(html);
				}
				parent.updateGoodsIds(ychser.getChosenIds());
            });
            parent.layer.close(index);
        })

    });
</script>
</html>